import time

from selenium.webdriver.common.by import By
from base.base import Base
from utils.utils import *


class Page1(Base):
    _USERNAME_INPUT = (By.ID, "userName")
    _PASSWORD_INPUT = (By.ID, "password")
    _VERIFY_INPUT = (By.ID, "randCode")
    _LOGIN_BUTTON = (By.ID, "but_login")
    _CAPTCHA_IMG = (By.ID, 'randCodeImage')

    def username(self,name:str):
        self.send_keys(self._USERNAME_INPUT,name)
    def username1(self):
        self.find(self._USERNAME_INPUT).clear()
    def password(self,pwd:str):
        self.send_keys(self._PASSWORD_INPUT, pwd)
    def password1(self):
        self.find(self._PASSWORD_INPUT).clear()
    def code(self, code: str):
        self.send_keys(self._VERIFY_INPUT, code)
        return self
    def click_login(self):
        self.click(self._LOGIN_BUTTON)
    def yzm(self):
        # 设置隐式等待时间为5秒
        self.driver.implicitly_wait(5)
        self.find(self._CAPTCHA_IMG).screenshot('a.png')
        code=get_code('a.png')
        print(code)
        return str(code)

    def login(self,name,pwd,code):
        self.username1()
        self.username(name)
        self.password1()
        self.password(pwd)
        self.code(code)
        self.click_login()